package com.app.springbootinit.controller;


import com.app.springbootinit.model.Products;
import com.app.springbootinit.service.ProductsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;



@RestController
@RequestMapping("/products")
public class ProductController {
  
    @Resource
    ProductsService productService;


    // 添加产品接口
    @PostMapping("/insert")
    public boolean saveProduct(@RequestBody Products product) {
        return productService.saveProduct(product);
    }

    // 根据ID删除产品接口
    @DeleteMapping("/{id}")
    public boolean removeProductById(@PathVariable int id) {
        return productService.removeProductById(id);
    }

    // 更新产品接口
    @PutMapping
    public boolean updateProduct(@RequestBody Products product) {
        return productService.updateProduct(product);
    }

    // 根据ID查询产品接口
    @GetMapping("/{id}")
    public Products getProductById(@PathVariable int id) {
        return productService.getProductById(id);
    }

    // 查询所有产品接口
    @GetMapping
    public List<Products> listAllProducts() {
        return productService.listAllProducts();
    }
}